<?php
namespace Shop\Controller;
use Think\Controller;

class UserController extends BaseController{


	//会员中心首页
	public function index(){
		$auth = auth_check(C('auth_code'),$_SERVER['HTTP_HOST']);
		if (!$auth) {
			echo "未授权或授权已过期";exit;
		}

		$userid = session('user');
 
		$userinfo = M('user')->where("id = {$userid['id']}")->find();

		//下线总数
		$userinfo['t_account'] = M('user')->where("t_id = {$userid['id']}")->count() ? : 0;
		
		//今日盈亏
		$map = array();
		$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
		$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
	
		$map['time'] = array(array('egt',$beginToday),array('elt',$endToday),'and');
		$map['state'] = 1;
		$map['userid'] = $userid['id'];

		$yinkui = M('order')->field("sum(add_points) as sum_add,sum(del_points) as sum_del")->where($map)->find();
		$userinfo['ying'] = $yinkui['sum_add'] - $yinkui['sum_del'];

		//今日推广佣金
		$map_y['time'] = array(array('egt',$beginToday),array('elt',$endToday),'and');
		$map_y['t_uid'] =  $userid['id'];
		$yong = M('push_money')->where($map_y)->field("sum(money) as money")->find();

		$userinfo['yong_today'] = $yong['money'] ? : 0;
		$kefu = M('config')->where("id = 1")->find();
		$this->assign('kefu',$kefu);

		$is_weixin = is_weixin();
		$this->assign('is_weixin',$is_weixin);

		$this->assign("user",$userinfo);
		$this->display();
	}

	
	
	public function tkInfo(){
        $userid = session('user');
        $info=M('user')->where('id='.$userid['id'])->find();
 
        $this->assign('info',$info);
	    $this->display();
    }
	public function tkInfo2(){
        $userid = session('user');
        $info=M('user')->where('id='.$userid['id'])->find();
 
        $this->assign('info',$info);
	    $this->display();
    }

    public function tkInfoPost(){
        if(IS_POST){
            $data=$_POST;
            $uid=$data['uid'];
            $db=M('user');
            //查询
            $info=$db->where('id='.$uid)->find();
            //判断登陆密码是否正确
            
            if(md5($data['tk_pwd'])!=$info['tk_password']){
                $this->error('提款密码错误');
            }
            $userdata=array(
                'bank'=>$data['bank'],
                'bank_name'=>$data['bank_name'],
                'bank_user'=>$data['bank_user']
            );
            //存入数据
            $res=$db->where('id='.$uid)->save($userdata);
            if($res){
                $this->success('保存成功');
            }else{
                $this->error('保存失败');
            }
        }


    }
	
	
	//佣金转钱包
	public function yzqpage(){
		$this->display();
	}

	//佣金转钱包
	public function fzqpage(){
		$this->display();
	}

	public function uppwd(){
		$this->display();
	}
	







    /**
     * 转让post
     */
    public function transferPost(){
        if(IS_POST){

            $userid = session('user');
            $data=$_POST;
            $zruserid=$data['userid'];//转给人
            $zrmoney=$data['money'];//转出金额
            $pass=$data['pass'];//提现密码
            $db=M('user');
            $msgdb=M('transaction');
            //操作被操作人
            $zruserwhere=array('id'=>$zruserid);
            //操作session用户并记录
            $sessioninfowhere=array('id'=>$userid['id']);
            $sessioninfo=$db->where($sessioninfowhere)->find();
            if(empty($pass)){
                $this->error('提现密码不能为空');
            }
            if(md5($pass)!=$sessioninfo['tk_password']){
                $this->error('提现密码错误');
            }
            if($zrmoney>$sessioninfo['points']){
                $this->error('元宝不足,请充值后在操作');
            }

            if($zruserid==$userid['id']){
                $this->error('您是要转给自己？想多了');
            }

            $res=$db->where($zruserwhere)->find();
            if($res==0){
                $this->error('ID错误,请重新核对用户ID');
            }

            //获取当前最新用户余额-转出金额=现在金额并更新用户金额
//            $zcusermoney=array(
//                'points'=>$sessioninfo['points']-$zrmoney
//            );
//            $zcdata=$db->where($sessioninfowhere)->setField($zcusermoney);
//           if($zcdata){
                //记录转出
                $msgdata=array(
                    'userid'=>$sessioninfo['id'],
                    'username'=>$sessioninfo['nickname'],
                    'xymoney'=>$sessioninfo['points'],
                    'zcmoney'=>$zrmoney,
                    'zruserid'=>$zruserid,
                    'zrusername'=>$res['nickname'],
                    'zrmoney'=>$zrmoney,
                    'type'=>1,
                    'time'=>time(),
                    'status'=>0
                );
                $msg=$msgdb->add($msgdata);
                //获取转入人当前余额+转入金额=现在金额并更新用户金额
              //  $zrusermoney=array(
             //       'points'=>$res['points']+$zrmoney
            //    );
             //   $zrdata=$db->where($zruserwhere)->setField($zrusermoney);
              //  if($zrdata){
                    $mssgdata=array(
                        'userid'=>$sessioninfo['id'],
                        'username'=>$sessioninfo['nickname'],
                        'xymoney'=>$sessioninfo['points'],
                        'zcmoney'=>$zrmoney,
                        'zruserid'=>$zruserid,
                        'zrusername'=>$res['nickname'],
                        'zrmoney'=>$zrmoney,
                        'type'=>2,
                        'time'=>time(),
                        'status'=>0,
                        'orderid'=>$msg
                    );
                    $mssg=$msgdb->add($mssgdata);

              //  }
                $this->success('转让成功等待审核');
        //    }else{
         //       $this->error('转让失败');
        //    }
        }

    }



    /**
     * 转让记录
     */
    public function getlastzr(){
        $userid = session('user');
        $msgdb=M('transaction');

        $where=array(
            'userid'=>$userid['id'],
            'type'=>1
        );
        $count = $msgdb->field("sum(zcmoney) as sum_points,count(id) as count")->where($where)->find();
        $page = new \Think\Page($count['count'],10);
        $show = $page->show();
        $res=$msgdb->where($where)->limit($page->firstRow.','.$page->listRows)->order("id desc")->select();
        $this->assign('show',$show);
        $this->assign('list',$res);
        $this->display();
    }

    /**
     * 转进记录
     */
    public function getlastzj(){
        $userid = session('user');
        $msgdb=M('transaction');
        $where=array(
            'zruserid'=>$userid['id'],
            'type'=>2
        );
        $count = $msgdb->field("sum(zcmoney) as sum_points,count(id) as count")->where($where)->find();
        $page = new \Think\Page($count['count'],10);
        $show = $page->show();
        $res=$msgdb->where($where)->limit($page->firstRow.','.$page->listRows)->order("id desc")->select();
        $this->assign('show',$show);
        $this->assign('list',$res);
        $this->display();
    }


    //提款密码
    public function tkppwd(){
        $userid = session('user');
        if (C('is_weixin') == '1' && is_weixin()) {
            $data=array(
                'is_weixin'=>1
            );

            $this->assign('weixin',$data);
        }else{
            echo is_weixin();
        }
        $where=array(
            'id'=>$userid['id'],

        );
        $res=M('user')->where($where)->find();
        $this->assign('info',$res);
        $this->display();
    }
    /**
     * 判断是web登录/微信登录
     * web登录输入登录密码,微信登录直接输入两次密码
     *
     */
    public function tkpwdpost(){
        if(IS_POST){
            $data=$_POST;
            $id=$data['uid'];
            $res=M('user')->where('id='.$id)->find();
            if(empty($res['tk_password'])){
                if (C('is_weixin') == '1' && is_weixin()) {

                    //保存提现密码
                    $mess=array(
                        'tk_password'=>md5($data['pwd'])
                    );
                    $pwds=M('user')->where('id='.$id)->save($mess);
                    if($pwds){
                        $this->success('提现密码设置成功,',U('/Shop/Run/index'),1);
                    }else{
                        $this->error('提现密码设置失败');
                    }
                }else{

                    //输入的登录密码MD5加密
                    $pwd=md5($data['loginpwd']);
                    //if($pwd==$res['password']){
                        //判断输入的提现密码是否等于登录密码
//                        if($data['pwd']==$data['loginpwd']){
//                            $this->error('输入的提现密码不能与登录密码一致');
//                        }
                        //保存提现密码
                        $mess=array(
                            'tk_password'=>md5($data['pwd'])
                        );
                        $pwds=M('user')->where('id='.$id)->save($mess);
                        if($pwds){
                            $this->success('提现密码设置成功,',U('/Shop/Run/index'),1);
                        }
//                    }else{
//                        $this->error('登录密码输入错误');
//                    }

                }
            }else{
                //旧密码
                $pwd=md5($data['loginpwd']);
                if($pwd==$res['tk_password']){
                    //登录密码

                    $logpwd=md5($data['pwd']);
                    if($logpwd==$res['password']){
                        $this->error('提现密码不能与登录密码一致');
                    }

                    $mess=array(
                        'tk_password'=>md5($data['pwd'])
                    );
                    $pwds=M('user')->where('id='.$id)->save($mess);
                    if($pwds){
                        $this->success('提现密码设置成功,',U('/Shop/Run/index'),1);
                    }

                }else{
                    $this->error('旧的提现密码输入错误!');
                }

            }



        }

    }
	
	

	//修改密码
	public function dopwd(){
		$old_pwd = I('old_pwd');
		$pwd = I('pwd');
		$user = session('user');
		$userinfo = M('user')->where("id = {$user['id']}")->find();
		if ($userinfo['password'] != md5($old_pwd)) {
			$this->error("旧密码不正确");
		}

		$res = M('user')->where("id = {$user['id']}")->save(array('password'=>md5($pwd)));

		if ($res) {
			$this->success('修改密码成功，跳转中~',U('Home/User/index'),1);
		} else {
			$this->error('修改密码失败');
		}

	}

	//佣金转钱包
	public function yzq(){
		$money = I('money');
		$uid = session('user');
		$user = M('user')->where("id = {$uid['id']}")->find();

		if (intval($user['yong']) < intval($money)) {
			$this->error("佣金不足，请确认");
		}

		$User = M('user');
		$User->startTrans();
		$res1 =  $User->where("id = {$uid['id']}")->setDec('yong',$money);
		$res2 =  $User->where("id = {$uid['id']}")->setInc('points',$money);

		if ($res1 && $res2) {
			$User->commit(); 
			$this->success('转入成功，跳转中~',U('Home/User/index'),1);
		} else {
			$User->rollback(); 
			$this->error('转入失败，请重试');
		}
	}

	//佣金转钱包
	public function fzq(){
		$money = I('money');
		$uid = session('user');
		$user = M('user')->where("id = {$uid['id']}")->find();

		if (intval($user['fanshui']) < intval($money)) {
			$this->error("返水金额不足，请确认");
		}

		$User = M('user');
		$User->startTrans();
		$res1 =  $User->where("id = {$uid['id']}")->setDec('fanshui',$money);
		$res2 =  $User->where("id = {$uid['id']}")->setInc('points',$money);

		if ($res1 && $res2) {
			$User->commit(); 
			$this->success('转入成功，跳转中~',U('Home/User/index'),1);
		} else {
			$User->rollback(); 
			$this->error('转入失败，请重试');
		}
	}

	//我的下线
	public function offline(){
		$id = I('id');
		// $userinfo = session('user');
		$member = M('user');
		$count = $member->where("t_id = {$id}")->count();
		$page = new \Think\Page($count,10);
		$show = $page->show();
		$list = $member->where("t_id = {$id}")->limit($page->firstRow.','.$page->listRows)->order("id ASC")->select();
		
		
		foreach ($list as $key => $value) {
			$yong = M('push_money')->where("id={$value['id']}")->field("SUM(money) as money")->find();
			$list[$key]['yong'] = $yong['money'] ? : 0;
		}

		//直属线下列表id
		$all_off = $member->field("id")->where("t_id = {$id}")->select();
		//三级下级列表id
		$ids = array();
		$ids2 = array();
		$ids3 = array();
		foreach ($all_off as $key => $value) {
			$ids[] = $value['id'];
			$all_off2 = $member->field("id")->where("t_id = {$value['id']}")->select();
			if (!empty($all_off2)) {
				foreach ($all_off2 as $key2 => $value2) {
					$ids2[] = $value2['id'];
					$all_off3 = $member->field("id")->where("t_id = {$value2['id']}")->select();
					if (!empty($all_off3)) {
						foreach ($all_off3 as $key3 => $value3) {
							$ids3[] = $value3['id'];
						}
					}
				}
			}
		}
		$all_ids = array_merge($ids,$ids2,$ids3);
		$ids = implode(',', $ids);
		$all_ids = implode(',', $all_ids);

		$time = I('time');
		$start = strtotime(str_replace("+"," ",I('starttime')));
		$end = strtotime(str_replace("+"," ",I('endtime')));

		if($time){
			if ($time == 'today') {
				$start=mktime(0,0,0,date('m'),date('d'),date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			} elseif($time == 'yestoday') {
				$start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
			} elseif($time == 'week') {
				$start=mktime(0,0,0,date('m'),date('d')-6,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}  elseif($time == 'month') {
				$start=mktime(0,0,0,date('m'),date('d')-29,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}
		}
		$map = array();
		if ($start && $end) {
			$map['time'] = array(array('egt',$start),array('elt',$end),'and');
		}

		//每个会员的流水
		foreach ($list as $key => $value) {

			$user_order = M("order")->field("sum(add_points) as sum_add,sum(del_points) as sum_del")->where("userid={$value['id']} and state=1")->where($map)->find();
			$list[$key]['add_points'] = $user_order['sum_add'];
			$list[$key]['del_points'] = $user_order['sum_del'];
			$list[$key]['ying'] = $user_order['sum_add'] - $user_order['sum_del'];
		}


		$list_new = $this->_arraysort($list,'add_points');

		
		//所有下线上下分记录
		$add_fen = M('integral')->field("sum(points) as add_fen")->where("type = 1 and uid in (".$ids.")")->where($map)->find();

		$xia_fen = M('integral')->field("sum(points) as xia_fen")->where("type = 0 and uid in (".$ids.")")->where($map)->find();
		
		$integral['add_fen'] = $add_fen['add_fen'];
		$integral['xia_fen'] = $xia_fen['xia_fen'];

		//所有下线进项、出项流水
		$order = M("order")->field("sum(add_points) as sum_add,sum(del_points) as sum_del")->where("state=1 and userid in (".$ids.")")->where($map)->find();

		$order['ying'] = $order['sum_add'] - $order['sum_del'];

		//所得所佣金
		$yong = M('push_money')->field("sum(money) as sum_yong")->where("uid in (".$ids.")")->where($map)->find();

		//所有下三级下线的数据统计
		$add_fen_all = M('integral')->field("sum(points) as add_fen")->where("type = 1 and uid in (".$all_ids.")")->where($map)->find();

		$xia_fen_all = M('integral')->field("sum(points) as xia_fen")->where("type = 0 and uid in (".$all_ids.")")->where($map)->find();
		
		$integral_all['add_fen'] = $add_fen_all['add_fen'];
		$integral_all['xia_fen'] = $xia_fen_all['xia_fen'];

		//所有下线进项、出项流水
		$order_all = M("order")->field("sum(add_points) as sum_add,sum(del_points) as sum_del")->where("state=1 and userid in (".$all_ids.")")->where($map)->find();

		$order_all['ying'] = $order_all['sum_add'] - $order_all['sum_del'];

		//所得所佣金
		$yong_all = M('push_money')->field("sum(money) as sum_yong")->where("uid in (".$all_ids.")")->where($map)->find();	

		$this->assign('id',$id);
		$this->assign('show',$show);
		$this->assign('list',$list_new);
		$this->assign('integral',$integral);
		$this->assign('order',$order);
		$this->assign('yong',$yong);
		$this->assign('integral_all',$integral_all);
		$this->assign('order_all',$order_all);
		$this->assign('yong_all',$yong_all);
		$this->assign('total_money',$total_money);
		$this->assign('start',$start ?  date('Y-m-d H:i:s',$start) : '');
		$this->assign('end',$end ? date('Y-m-d H:i:s',$end) : '');
		$this->display();
	}


    private function _arraysort($arr,$field){
        $field_arr = array();
        foreach ($arr as $key=>$value)
        {
            $field_arr[$key] = $value[$field];
        }

        if(!empty($field_arr)&&!empty($arr))
        {
            array_multisort($field_arr,SORT_DESC,$arr);
        }
        return $arr;
    }

	//我的下线下注记录
	public function offxz(){
		$time = I('time');
		$map = array();

		$map['state'] = 1;
		$time = I('time');
		$start = strtotime(I('starttime'));
		$end = strtotime(I('endtime'));
		
		if($time){
			if ($time == 'today') {
				$start=mktime(0,0,0,date('m'),date('d'),date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			} elseif($time == 'yestoday') {
				$start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
			} elseif($time == 'week') {
				$start=mktime(0,0,0,date('m'),date('d')-6,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}  elseif($time == 'month') {
				$start=mktime(0,0,0,date('m'),date('d')-29,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}
		}

		if ($start && $end) {
			$map['time'] = array(array('egt',$start),array('elt',$end),'and');
		}

		$id = I('id');
		$map['is_under'] = 1;
		$map['userid'] = $id;
		$order = M('order');
		// $integral = M('integral');
		$count = $order->where($map)->count();
		$page = new \Think\Page($count,10);
		$show = $page->show();
		$list = array();
		$tj = $order->field("sum(add_points) as sum_add,sum(del_points) as sum_del")->where($map)->find();
		$list = $order->where($map)->limit($page->firstRow.','.$page->listRows)->order("id DESC")->select();

		$this->assign('list',$list);
		$this->assign('time',$time);
		$this->assign('id',$id);
		$this->assign('show',$show);
		$this->assign('tj',$tj);
		$this->assign('start',$start ?  date('Y-m-d',$start) : '');
		$this->assign('end',$end ? date('Y-m-d',$end) : '');
		$this->display();
	}

	//我的下线充值记录
	public function offcz(){
		$id = I('id');
		$map['uid'] = $id;
		
		$integral = M('integral');
		$time = I('time');
		$map = array();
		$map['uid'] = $id;
		$start = strtotime(I('starttime'));
		$end = strtotime(I('endtime'));
		
		if($time){
			if ($time == 'today') {
				$start=mktime(0,0,0,date('m'),date('d'),date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			} elseif($time == 'yestoday') {
				$start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
			} elseif($time == 'week') {
				$start=mktime(0,0,0,date('m'),date('d')-6,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}  elseif($time == 'month') {
				$start=mktime(0,0,0,date('m'),date('d')-29,date('Y'));
				$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
			}
		}

		if ($start && $end) {
			$map['time'] = array(array('egt',$start),array('elt',$end),'and');
		}

		
		$sum_data = array(
			'add' => 0,
			'xia' => 0,
		);
	

		$count = $integral->where($map)->count();
		$page = new \Think\Page($count,10);
		$show = $page->show();
		$sum_add = $integral->field("sum(points) as sum_add")->where("type = 1")->where($map)->find();
		$sum_data['add'] = $sum_add['sum_add'];
		$sum_xia = $integral->field("sum(points) as sum_add")->where("type = 0")->where($map)->find();
		$sum_data['xia'] = $sum_xia['sum_add'];
		$list = $integral->where($map)->limit($page->firstRow.','.$page->listRows)->order("id DESC")->select();
	
		for($i=0;$i<count($list);$i++){
			$list[$i]['user'] = M('user')->where("id = {$list[$i]['uid']}")->find();
		}

		$startline =  $start ? date('Y-m-d',$start) : '';
		$endline =  $start ? date('Y-m-d',$end) : '';

		$this->assign('nickname',$nickname);
		$this->assign('start',$startline);
		$this->assign('end',$endline);
		$this->assign('list',$list);
		$this->assign('id',$id);
		$this->assign('show',$show);
		$this->assign('sum_data',$sum_data);
		$this->assign('time',$time);
		$this->display();
	}

	//充值记录
	public function fenadd(){
		$uid = session('user')['id'];
		$member = M('integral');
		$count = $member->field("sum(points) as sum_points,count(id) as count")->where("type = 1  and uid = {$uid}")->find();

		$page = new \Think\Page($count['count'],10);
		$show = $page->show();
		$list = $member->where("type = 1 and uid = {$uid}")->limit($page->firstRow.','.$page->listRows)->order("id desc")->select();

		$this->assign('show',$show);
		$this->assign('count',$count);
		$this->assign('list',$list);
		$this->display();
	}

	//提现记录
	public function fenxia(){
		$uid = session('user')['id'];
		$member = M('integral');
		$count = $member->field("sum(points) as sum_points,count(id) as count")->where("type = 0  and uid = {$uid}")->find();
		$page = new \Think\Page($count['count'],10);
		$show = $page->show();
		$list = $member->where("type = 0 and uid = {$uid}")->limit($page->firstRow.','.$page->listRows)->order("id desc")->select();

		$this->assign('show',$show);
		$this->assign('list',$list);
		$this->assign('count',$count);
		$this->display();
	}

	public function xiazhu(){
			$t = I('t');
		$pkdata = F('pk10data');
		$map = array();
		if($t == 1){
			$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
			$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
		}
		if($t == 2){
			$beginToday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$endToday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
		}
		if($t == 3){
			$beginToday=mktime(0,0,0,date('m'),date('d')-2,date('Y'));
			$endToday=mktime(0,0,0,date('m'),date('d')-1,date('Y'))-1;
		}
		if($t == 4){
			$beginToday=0;
			$endToday=0;
		}
		if ($beginToday and $endToday) {
			$map['time'] = array(array('egt',$beginToday),array('elt',$endToday),'and');
		}
		$userinfo = session('user');
		$map['state'] = 1;
		$map['userid'] = $userinfo['id'];
		
		
		$order = M('order');
		$count = $order->where($map)->count();
		$points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")->where($map)->find();
		$points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
		$page = new \Think\Page($points_tj['count'],6);
		
		$show = $page->show();
		$list = $order->field("*")->where($map)->limit($page->firstRow.','.$page->listRows)->order("id DESC")->select();

		$number = array();
		for($i=0;$i<count($list);$i++){

			if(!in_array($list[$i]['number'], $number)){
				$number[] = $list[$i]['number'];
			}
			for($a=0;$a<count($number);$a++){
				if($list[$i]['number']==$number[$a]){
					$list1[$a]['number'] = $number[$a];
					$list1[$a]['order'][] = $list[$i];
				}
			}
		}
		
		//print_r($list1);
		$this->assign('list1',$list1);
		$this->assign('state',F('state'));
		$this->assign('number',$pkdata['next']['periodNumber']);
		$this->assign('list',$list);
		$this->assign('points_tj',$points_tj);
		$this->assign('show',$show);
		$this->assign('today',mktime(0,0,0,date('m'),date('d'),date('Y')));
		$this->assign('t',$t);
		$this->display();
	}
    //图片上传
    public function avatarUpload(){
        $uid = session('user')['id'];
        $config = array(
            'maxSize'    =>    3145728,
            'rootPath'   =>    './Uploads/member/',
            'savePath'   =>    '',
            'saveName'   =>    array('uniqid',''),
            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>    true,
            'subName'    =>    array('date','Ymd'),
        );
        $upload = new \Think\Upload($config);// 实例化上传类

        // 上传文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功

          $data=M('user')->where('id='.$uid)->save(array('headimgurl'=>'/Uploads/member/'.$info['file']['savepath'].$info['file']['savename']));
          if($data){
              $this->success('上传成功！');
          }

        }


    }
	
}
?>